<?php

function mysqlconnect()
{
	include('config.php');
	$con = mysql_connect($MYSQLSERVERNAME, $MYSQLUSERNAME, $MYSQLPASSWORD);
	if(!$con)
	{
		trigger_error("Problem connecting to server: ");
	}	
	$db =  mysql_select_db($MYSQLDBNAME, $con);
 	if(!$db)
	{
  		trigger_error("Problem selecting database: ");
	}	
	return $con;
}

function mysqldisconnect($con)
{
	$discdb = mysql_close($con);
 	if(!$discdb)
	{
		trigger_error("Problem disconnecting database: ");
	}	
}

function mysqlexecute_update($sql)
{
	$con = mysqlconnect();
	$result = mysql_query($sql, $con);
	if(!$result)
	{
		trigger_error("Problem updating data: ");
	}
	mysqldisconnect($con);
	return $result;
}

function mysqlexecute_query($sql)
{
	$con = mysqlconnect();
	$result = mysql_query($sql, $con);
	if(!$result)
	{
		trigger_error("Problem selecting data: ");
	}
	while($row = mysql_fetch_array($result, MYSQL_ASSOC))
	{
		$result_array[] = $row;
	}
	mysql_free_result($result);
	mysqldisconnect($con);
	return $result_array;
}

function mysqlexecute_insert($sql)
{
	$con = mysqlconnect();
	$result = mysql_query($sql, $con);
	if(!$result)
	{
		trigger_error("Problem Inserting data: ");
	}
	mysqldisconnect($con);
	return $result;
}

function mysqlexecute_delete($sql)
{
	$con = mysqlconnect();
	$result = mysql_query($sql, $con);
	if(!$result)
	{
		trigger_error("Problem Inserting data: ");
	}
	mysqldisconnect($con);
	return $result;
}
?>
